<!DOCTYPE html>


<html lang="zh-CN,en,default">
  

    <head>
      <meta charset="utf-8" />
       
      <meta name="keywords" content="阳小良,个人博客,程序猿,插画师,技术博客,人生感悟" />
       
      <meta name="description" content="不想做插画师的程序猿，不是好厨师" />
      
      <meta
        name="viewport"
        content="width=device-width, initial-scale=1, maximum-scale=1"
      />
      <title>零基础-搭建个人博客4-部署到github上 |  阳小良</title>
  <meta name="generator" content="hexo-theme-ayer">
      
      <link rel="shortcut icon" href="/favicon.ico" />
       
<link rel="stylesheet" href="/dist/main.css">

      
<link rel="stylesheet" href="/css/fonts/remixicon.css">

      
<link rel="stylesheet" href="/css/custom.css">
 
      <script src="https://cdn.staticfile.org/pace/1.2.4/pace.min.js"></script>
       
 

      <link
        rel="stylesheet"
        href="https://cdn.jsdelivr.net/npm/@sweetalert2/theme-bulma@5.0.1/bulma.min.css"
      />
      <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.0.19/dist/sweetalert2.min.js"></script>

      <!-- mermaid -->
      
      <style>
        .swal2-styled.swal2-confirm {
          font-size: 1.6rem;
        }
      </style>
    </head>
  </html>
</html>


<body>
  <div id="app">
    
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-tech/createBlogs/零基础-搭建个人博客4-部署到github上"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  零基础-搭建个人博客4-部署到github上
</h1>
 

      
    </header>
     
    <div class="article-meta">
      <a href="/2025/01/16/tech/createBlogs/%E9%9B%B6%E5%9F%BA%E7%A1%80-%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A24-%E9%83%A8%E7%BD%B2%E5%88%B0github%E4%B8%8A/" class="article-date">
  <time datetime="2025-01-16T15:13:14.000Z" itemprop="datePublished">2025-01-16</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/%E8%B0%8B%E7%94%9F%E6%89%8B%E6%AE%B5/">谋生手段</a> / <a class="article-category-link" href="/categories/%E8%B0%8B%E7%94%9F%E6%89%8B%E6%AE%B5/%E9%9B%B6%E5%9F%BA%E7%A1%80/">零基础</a> / <a class="article-category-link" href="/categories/%E8%B0%8B%E7%94%9F%E6%89%8B%E6%AE%B5/%E9%9B%B6%E5%9F%BA%E7%A1%80/%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2/">搭建个人博客</a>
  </div>
  
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">1.5k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">5 分钟</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <h2 id="本篇目的"><a href="#本篇目的" class="headerlink" title="本篇目的"></a>本篇目的</h2><blockquote>
<p>本地完成博客的建设后，部署到服务器上，接受广大网友的洗礼。</p>
</blockquote>
<h2 id="github环境配置："><a href="#github环境配置：" class="headerlink" title="github环境配置："></a>github环境配置：</h2><h3 id="1-注册-创建仓库-名称-："><a href="#1-注册-创建仓库-名称-：" class="headerlink" title="1.注册&amp;创建仓库(名称)："></a>1.注册&amp;创建仓库(名称)：</h3><blockquote>
<p>打开github仓库地址：</p>
<blockquote>
<p><a target="_blank" rel="noopener" href="https://github.com/login">https://github.com/login</a></p>
</blockquote>
<p>如果有账号直接登录，如果没有点击 create a account；</p>
<p>注册时需要关注您的用户名，英文字母数字组成，这个用户名也是你后续创建域名访问博客的二级域名。</p>
<p>创建完成用户后，可以回到个人主页，并在主页中寻找Create Repository来进行项目创建。</p>
<p>为后续github博客访问和域名映射顺利完成，这里我们注册的项目名称需要满足如下的要求：</p>
<blockquote>
<p>{你的用户名}.github.io</p>
</blockquote>
<p>比如我的用户名是sid2656，则我创建的仓库名称为：sid2656.github.io</p>
<p>其余保持默认即可，也可以填写一下描述信息。</p>
</blockquote>
<h3 id="2-hexo生成静态文件上传："><a href="#2-hexo生成静态文件上传：" class="headerlink" title="2.hexo生成静态文件上传："></a>2.hexo生成静态文件上传：</h3><blockquote>
<p>通过前置的博客基础配置和markDown文档的编写，我们已经完成了博客的基础内容。</p>
<p>这时候便可以开始尝试部署到代码仓库之中了。</p>
<blockquote>
<p>2.1 我们将本地根目录中的public文件夹删除掉</p>
<p>2.2 将我们刚刚在步骤一中创建的仓库clone到本地，并与hexo的默认文件夹名称相同，代码如下：</p>
<blockquote>
<p>git clone <a target="_blank" rel="noopener" href="https://github.com/%7B%E4%BD%A0%E7%9A%84%E7%94%A8%E6%88%B7%E5%90%8D%7D/%7B%E4%BD%A0%E7%9A%84%E7%94%A8%E6%88%B7%E5%90%8D%7D.github.io.git">https://github.com/{你的用户名}/{你的用户名}.github.io.git</a> public</p>
</blockquote>
</blockquote>
<blockquote>
<p>2.3 完成仓库的clone之后，可以进入到本地根目录执行如下命令生成静态文件：</p>
<blockquote>
<p>hexo g</p>
</blockquote>
</blockquote>
<p>这样我们便完成了静态代码的生成，并将本地目录与github的项目进行了关系绑定。<br>接下来我们进入到  {你的根目录}&#x2F;public  文件夹中，执行如下的命令：</p>
<blockquote>
<p>git pull</p>
</blockquote>
<blockquote>
<p>git add .</p>
</blockquote>
<blockquote>
<p>git commit -m “init blog”</p>
</blockquote>
<blockquote>
<p>git push</p>
</blockquote>
<p>这个过程中不要切换分支，使用默认的master分之即可；上面四步的操作分别是：<br>代码拉取；本地文件添加到git管理；本地文件确认；本地文件提交到远程；</p>
<p>至此，我们的代码相关工作已经全部完成了！</p>
<p>注意：代码提交后预计十分钟生效！！</p>
</blockquote>
<h3 id="3-仓库的pages服务设置："><a href="#3-仓库的pages服务设置：" class="headerlink" title="3.仓库的pages服务设置："></a>3.仓库的pages服务设置：</h3><blockquote>
<p>在github网站打开你的仓库页面，并点击setting的页签</p>
<p><img src="https://files.sid2656.space/tech/createBlogs/gitpages.jpg" alt="个人博客" title="github pages"></p>
<p>在setting页签下面找到pages服务，再沿着右侧的提示，找到分支，选定默认分支master；然后点击保存处理。</p>
<p>设置后会提示如下的信息，您可以自定义域名，或者使用默认的域名。这里我们先使用github提供的域名。</p>
<p><img src="https://files.sid2656.space/tech/createBlogs/domain.jpg" alt="个人博客" title="github domain"></p>
<p>在完成步骤2种的代码提交后10分钟，我们访问步骤3种，给到我们的域名看看效果：</p>
<p><img src="https://files.sid2656.space/tech/createBlogs/bloghome.jpg" alt="个人博客" title="github domain"></p>
<p>至此，我们的博客基础配置全部完成！</p>
</blockquote>
<h3 id="4-自定义域名（备案）："><a href="#4-自定义域名（备案）：" class="headerlink" title="4.自定义域名（备案）："></a>4.自定义域名（备案）：</h3><blockquote>
<p>理论上在没有被限制的情况下，我们是可以通过github的项目域名进行博客的访问：</p>
<blockquote>
<p>https:&#x2F;&#x2F;{你的用户名}.github.io</p>
</blockquote>
<p>但是因为存在部分不可抗力的原因，导致我们无法直接通过github的域名进行博客的访问；</p>
<p>此时，我们就只能想办法通过一定的规则手段配置，使得个人的博客网站可以被正常访问。这里我罗列两条方案；</p>
<blockquote>
<p>方案一：</p>
<p>申请自己的域名，并在云厂商购买一台服务器，比如在阿里云购买一天最低配服务器，并申请公网IP和固定带宽；</p>
<p>这样，您便可以通过阿里云服务器进行自己域名的解析和重定向；一般是需要在您在自己国内的服务器上面安装Nginx或者其他服务代理转发的后台服务。</p>
<p>另外，由于您使用的是国内服务器，您的域名需要解析到您服务器的公网ip，根据ICP备案的要求，您的域名还需要经历云厂商的服务器进行IP的绑定，做备案后才能投入使用。</p>
</blockquote>
<p>理论上来说方案一是可行的，但是因为个人原因，我没有进行尝试，有尝试的小伙伴，可以将结果反馈一下。</p>
<p>这个方案的目的是国外的域名改为自己的域名，并通过正常的备案流程进行访问，理论上来说只要不提供反对内容应该是不会要问题的。</p>
<blockquote>
<p>方案二：</p>
<p>使用海外的域名解析网站，比如：Cloudflare；</p>
<p>我们可以将自己的域名的DNS解析服务器修改为cloudflare提供的服务器，其提供的解析域名会根据重定向后的规则，找到需要访问的真是IP地址，<br>这样在我们访问域名时，便不会因为重定向的限制和不可抗因素被重定向后的域名给截断请求。</p>
<p>cloudflare还会根据您实际访问ip的地址分配就近的CDN进行内容的缓存，无形中加快了您域名跨区域访问的速度。当然这种CDN服务在国内是需要收费的，但是cloudflare是可以提供免费支持的。</p>
</blockquote>
<p>方案二的目的是直接跳过国内的DNS，直接到国外可用的DNS去解析内容，然后直接返回数据内容，这样返回的内容并不会被GFW拦截。</p>
<p>我们可以看到不同方案的对比，理论上来说方案一的访问速度回被方案二更快一些，毕竟站点在国内，但是方案二通过国内CDN和免费解析等手段基本上也能达到我们预期的诉求。</p>
<p>综上所述，我按照我自己的实际使用场景，选择了方案二进行域名的解析。</p>
</blockquote>
 
      <!-- reward -->
      
      <div id="reword-out">
        <div id="reward-btn">
          打赏
        </div>
      </div>
      
    </div>
    

    <!-- copyright -->
    
    <div class="declare">
      <ul class="post-copyright">
        <li>
          <i class="ri-copyright-line"></i>
          <strong>版权声明： </strong>
          
          本博客所有文章除特别声明外，著作权归作者所有。转载请注明出处！
          
        </li>
      </ul>
    </div>
    
    <footer class="article-footer">
       
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/hexo/" rel="tag">hexo</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E8%B0%8B%E7%94%9F%E6%89%8B%E6%AE%B5/" rel="tag">谋生手段</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E9%9B%B6%E5%9F%BA%E7%A1%80/" rel="tag">零基础</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2025/01/17/tech/createBlogs/%E9%9B%B6%E5%9F%BA%E7%A1%80-%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A25-%E8%B5%84%E6%BA%90%E5%AD%98%E5%82%A8/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            零基础-搭建个人博客5-资源存储
          
        </div>
      </a>
    
    
      <a href="/2025/01/15/tech/createBlogs/%E9%9B%B6%E5%9F%BA%E7%A1%80-%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A23-%E5%8D%9A%E5%AE%A2%E7%8E%AF%E5%A2%83/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">零基础-搭建个人博客3-博客环境</div>
      </a>
    
  </nav>

  
   
     
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2011-2025
        <i class="ri-heart-fill heart_icon"></i> 阿良
      </li>
    </ul>
    <ul>
      <li>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>访问人数:<span id="busuanzi_value_site_uv"></span></span>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>浏览次数:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
        <li>
          <a href="https://beian.miit.gov.cn/" target="_black" rel="nofollow">京ICP备14051636号-6</a>
        </li>
        
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
      </li>
    </ul>
  </div>
</footer>    
    </main>
    <div class="float_btns">
      <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

    </div>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="阳小良"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories/">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories/%E5%8E%9F%E8%91%97/">原著</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories/%E4%BA%94%E5%91%B3%E6%9D%82%E9%99%88/%E5%A4%A9%E6%B6%AF%E6%B5%B7%E8%A7%92/">旅行</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories/%E8%B0%8B%E7%94%9F%E6%89%8B%E6%AE%B5/">技术</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories/%E6%8A%95%E8%B5%84%E8%87%AA%E5%B7%B1/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/">读书</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" target="_blank" rel="noopener" href="https://hi.huitu.com/1145549/">摄影</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" target="_blank" rel="noopener" href="https://space.bilibili.com/3546831053129882/channel/seriesdetail?sid=4562367&ctype=0">画廊</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">友链</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/2011/02/14/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="搜索">
        <i class="ri-search-line"></i>
      </a>
      
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/images/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/images/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/js/jquery-3.6.0.min.js"></script>
 
<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->
 
<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: ".tocbot",
    contentSelector: ".article-entry",
    headingSelector: "h1, h2, h3, h4, h5, h6",
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: "main",
    positionFixedSelector: ".tocbot",
    positionFixedClass: "is-position-fixed",
    fixedSidebarOffset: "auto",
  });
</script>

<script src="https://cdn.staticfile.org/jquery-modal/0.9.2/jquery.modal.min.js"></script>
<link
  rel="stylesheet"
  href="https://cdn.staticfile.org/jquery-modal/0.9.2/jquery.modal.min.css"
/>
<script src="https://cdn.staticfile.org/justifiedGallery/3.8.1/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->
 <!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.staticfile.org/photoswipe/4.1.3/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.staticfile.org/photoswipe/4.1.3/default-skin/default-skin.min.css">
<script src="https://cdn.staticfile.org/photoswipe/4.1.3/photoswipe.min.js"></script>
<script src="https://cdn.staticfile.org/photoswipe/4.1.3/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script> 
<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->
 
<script src="/js/busuanzi-2.3.pure.min.js"></script>
 
<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->

<!-- CanvasBackground -->

<script>
  if (window.mermaid) {
    mermaid.initialize({ theme: "forest" });
  }
</script>


    
    

  </div>
</body>

</html>